﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModelDinhMuc.Model;
namespace TinhNguyenVatLieuSanBay
{
    public partial class FrmTimKiemChuyenBay : Form
    {
        DINHMUCSANBAYDB db = new DINHMUCSANBAYDB();
        private IList<ChuyenBay> lstchuyenbay;
        public ChuyenBay chuyenbay; 
        public FrmTimKiemChuyenBay(string mamaybay)
        {
            InitializeComponent();
            IntChuyenBay();
            txttimkiem.Text = mamaybay;
        }

        private void IntChuyenBay()
        {
            lstchuyenbay = db.SelectAllChuyenBay().ExecuteTypedList<ChuyenBay>();
            if(lstchuyenbay!=null && lstchuyenbay.Count>0)
            {
                chuyenBayBindingSource.DataSource = lstchuyenbay;
            }
        }

        private void txttimkiem_TextChanged(object sender, EventArgs e)
        {
            IList<ChuyenBay> lsttmp;
            lsttmp = lstchuyenbay.Where(x => x.MaMB.Contains(txttimkiem.Text.ToUpper().Trim())).ToList();
            chuyenBayBindingSource.DataSource = lsttmp;
        }

        private void gvchuyenbay_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var item = gvchuyenbay.CurrentRow.DataBoundItem as ChuyenBay;
            chuyenbay = item;
            this.Close();
        }

        private void FrmTimKiemChuyenBay_FormClosed(object sender, FormClosedEventArgs e)
        {
            var item = gvchuyenbay.CurrentRow.DataBoundItem as ChuyenBay;
            chuyenbay = item;
        }
    }
}
